﻿@{
    ViewBag.Title = "Buttons";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@model IEnumerable<YJ.Data.Model.AppLibraryButtons>
<form method="post" id="form1" >
@Html.AntiForgeryToken()
<div class="querybar">
    <table cellpadding="0" cellspacing="1" border="0" width="100%">
        <tr>
            <td>
                名称：<input type="text" class="mytext" id="Title" name="Title" value="@ViewBag.Title1" style="width:150px" />
                <input type="button" name="Search" onclick="query(null, 1);" value="&nbsp;&nbsp;查&nbsp;询&nbsp;&nbsp;" class="mybutton" />
                <input type="button" onclick="add(); return false;" value="添加按钮" class="mybutton" />
                <input type="button" id="delbutton" name="delbutton" onclick="del(); return false;" value="删除所选" class="mybutton" />
            </td>
        </tr>
    </table>
</div>
<table id="listtable"></table>
<div class="buttondiv"></div>
</form>
<script type="text/javascript">
    var appid = '@Request.QueryString["appid"]';
    var iframeid = '@Request.QueryString["tabid"]';
    var dialog = top.mainDialog;
    var curPageSize = '@Request.QueryString["pagesize"]';
    var curPageNumber = '@Request.QueryString["pagenumber"]';
    $(function ()
    {
        $("#listtable").jqGrid({
            url: RoadUI.Core.rooturl() + "/Menu/ButtonsQuery",
            postData: { "__RequestVerificationToken": $("input[name='__RequestVerificationToken']").val(), appid: appid },
            mtype: 'POST',
            datatype: "json",
            colNames: ['名称', '图标', '执行脚本', '说明', '排序', ''],
            colModel: [
                { name: 'Name', index: 'Name' },
                { name: 'Ico', index: 'Ico' },
                { name: 'Events', index: 'Events' },
                { name: 'Note', index: 'Note' },
                { name: 'Sort', index: 'Sort' },
                { name: 'Opation', index: '', sortable: false, width: 50 }
            ],
            sortname: "Name",
            sortorder: "asc",
            height: '100%',
            multiselect: true,
            width: $(window).width(),
            loadComplete: function ()
            {
                var gridObj = $("#listtable");
                var records = gridObj.getGridParam("userData");
                curPageSize = records.pagesize;
                curPageNumber = records.pagenumber;
                $(".buttondiv").html(RoadUI.Core.getPager1(records.total, records.pagesize, records.pagenumber, "query"));
            }
        });

    });
    $(window).resize(function ()
    {
        $("#listtable").setGridWidth($(window).width());
    });
    function query(size, number)
    {
        var data = {
            __RequestVerificationToken: $("input[name='__RequestVerificationToken']").val(),
            Title: $("#Title").val(), appid: appid,
            pagesize: size || curPageSize, pagenumber: number || curPageNumber
        };
        $("#listtable").setGridParam({ postData: data }).trigger("reloadGrid");
    }
    function checkAll(checked)
    {
        $("input[name='checkbox_app']").prop("checked", checked);
    }
    function del()
    {
        var rowIds = $("#listtable").jqGrid('getGridParam', 'selarrrow');
        if (rowIds.length == 0)
        {
            alert('您没有选择要删除的按钮!');
            return false;
        }
        if (!confirm('您真的要删除所选按钮吗?'))
        {
            return false;
            document.forms[0].action = 'ButtionsDelete?1=1' + '@Html.Raw(ViewBag.Query)';
            document.forms[0].submit();
        }
        $.ajax({
            url: RoadUI.Core.rooturl() + "/Menu/ButtionsDelete?1=1" + "@Html.Raw(ViewBag.Query)" + "&pagesize=" + curPageSize + "&pagenumber=" + curPageNumber,
            data: { "ids": rowIds.join(","), "__RequestVerificationToken": $("input[name='__RequestVerificationToken']").val() },
            type: "post",
            success: function (txt)
            {
                alert(txt);
                query();
            }
        });
        return true;
    }
    function add(id)
    {
        dialog.open({
            id: "window_" + appid.replaceAll('-', ''), title: "编辑按钮",
            width: 700, height: 450,
            url: '/Menu/ButtionsEdit?butid=' + (id || "") + '@Html.Raw(ViewBag.Query)' + "&pagesize=" + curPageSize + "&pagenumber=" + curPageNumber, opener: parent, openerid: iframeid
        });
    }

</script>